package com.aaa.stock.controller.medic;

import com.aaa.entity.Medicines;
import com.aaa.entity.Producer;
import com.aaa.entity.Role;
import com.aaa.stock.service.medic.StoMediService;
import com.aaa.stock.vo.MedicinesVo;
import com.aaa.stock.vo.ProducerVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stock/medic/med")
public class StockmedicController {
    @Autowired
    private StoMediService stoMediService;
//查全部
    @PostMapping("getAll/{currentPage}/{pageSize}")
    public Result<IPage<Medicines>> medicList(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody MedicinesVo medicinesVo
    ){
        return stoMediService.findByListtion(currentPage,pageSize,medicinesVo);
    }
//接口
    @PostMapping("/getMedicAll")
    public Page<Medicines> medicines(@RequestBody MedicinesVo medicinesVo){
        return stoMediService.getMedicAll(medicinesVo);
    }
    //删除
    @DeleteMapping("deleteMedic/{medicinesIds}")
    public Result<Map<String,Object>> deleteMedic(@PathVariable Long medicinesIds){
        return stoMediService.deleteMedic(medicinesIds);
    }
    //批量删
    @PostMapping("delAll")
    public Result delAll(@RequestBody List<Medicines> medicines){
        medicines.forEach((Medicines med)->{
            boolean b =stoMediService.removeById(med.getMedicinesId());
        });
        return new Result(2000,"成功");
    }
    //添加修改
    @PostMapping("andMedic")
    public Result addMedic(@RequestBody Medicines medicines){
        stoMediService.saveOrUpdate(medicines);
        return new  Result(2000,"成功");
    }
    // 远程调用 药品 修改库存
    @GetMapping("medicinesInventory")
    public Boolean medicinesInventory(@RequestParam String num,@RequestParam String itemName){

        return stoMediService.medicinesInventory(num,itemName);
    }
}
